package com.cj.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cj.common.utils.DateUtil;
import com.cj.common.utils.StrUtil;
import com.cj.order.dao.FileOrderMapper;
import com.cj.order.entity.FileOrder;
import com.cj.order.service.FileOrderService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * @Author cheng jun
 * @Description:
 * @Date 2021/7/12 17:35
 */
@Service
public class FileOrderServiceImpl extends ServiceImpl<FileOrderMapper, FileOrder> implements FileOrderService {
    @Override
    public boolean saveOrder(Map<String, Object> map) {
        Assert.notNull(map.get("orderId"), "订单id不能为空");
        Assert.notNull(map.get("orderName"), "订单名称不能为空");
        Assert.notNull(map.get("creationTime"), "创建时间不能为空");
        Assert.notNull(map.get("updateTime"), "更新时间不能为空");

        // 保存订单
        FileOrder order = new FileOrder();
        order.setId(StrUtil.getUuid32());
        order.setOrderId(String.valueOf(map.get("orderId")));
        order.setOrderName(String.valueOf(map.get("orderName")));
        order.setCreationTime(DateUtil.strConvetDate(String.valueOf(map.get("creationTime"))));
        order.setUpdateTime(DateUtil.strConvetDate(String.valueOf(map.get("updateTime"))));
        boolean flag = this.save(order);
        return flag;
    }
}
